<template>
	<view>
		<view class="" v-if="list.length>0">
			<view class="list"  v-for="(item, index) in list" :key="index" @click="moveTo(item)">
				<view class="title">{{ item.type }}</view>
				<view class="num">{{ item.num }}</view>
				<image :src="src" mode="" class="icon"></image>
			</view>
		</view>
		<view class="list" @click="about()">
			<view class="title">关于护士小鹿</view>
			<view class="num">{{edition?'版本号'+edition:''}}</view>
			<image :src="src" mode="" class="icon"></image>
		</view>
		<view class="out_back" @click="outBack">退出登录</view>
		<uni-popup ref="popup" type="dialog">
		   <!-- <uni-popup-dialog :type="msgType" cancelText="关闭" confirmText="同意" title="通知" content="欢迎使用 uni-popup!" @confirm="dialogConfirm"
		        @close="dialogClose"></uni-popup-dialog> -->
		      
		   <view class="uni-popup">
		   <view class="title">确定要注销账号吗？</view>
		   <view class="content">
		    <view class="ltitle">
		     <img src="@/static/icon/mine/warn.png" alt="" srcset="">
		     注销须知</view>
		    <view class="li">注销账号后将进入15天冻结期</view>
		    <view class="li">冻结期内重新登录视为撤销注销</view>
		    <view class="li">超过15天冻结期未登录应用内所有的数据将被清空</view>
		    <view class="li">数据清空无法恢复</view>
		    <view class="li">如因注销账号造成一切损失，平台不承担任何责任</view>
		   </view>
		   <view class="btns">
		    <view class="left" @click="handleCancle">取消</view>
		    <view class="right" :class="{'red':count==0}" @click="handleAccountCanceldid">确定
		    <text v-if="count>0">{{count}}s</text>
		    </view>
		   </view>
		   </view>
		  </uni-popup>
	</view>
</template>

<script>
import {uniConfirm} from '@/components/uni-ui/uni-confirm/uni-confirm.vue'
import uniPopup from '@/components/uni-ui/uni-popup/uni-popup.vue';
import { deleteLogined } from '@/apis/login/index.js';
import { writeOff, writeOffJudge } from '@/apis/nurse/index.js';
export default {
	data() {
		return {
			timer:null,
			count:5,
			confirmShow:false,
			uuid: this.$store.state.uuid,
			src: '../../../static/icon/set-code/nav-back.png',
			cache: '', //缓存
			edition: '', //版本号
			list: [
				{
					type: '修改手机号',
					url: '../change-phone/change-phone',
					state: 1
				},
				{
					type: '修改登录密码',
					url: '../../login-register/input-password/input-password',
					state: 2
				},
				{
					type: '修改提现密码',
					url: '../change-phone/change-phone',
					state: 7
				},
				{
					type: '清除缓存',
					num: ''
				},
				{
					type: '注销账号'
				}
			]
		};
	},
	onShow() {
		this.getCache();
		this.getNow();
	},
	methods: {
		//获取缓存
		getCache() {
			var _this = this;
			//#ifdef APP-PLUS
			// 使用plus.cache.calculate 获取应用的缓存大小，
			plus.cache.calculate(function(size) {
				//size是多少个字节单位是b
				//你可以做下面相应的处理
				if (size < 1024) {
					_this.cache = size + 'B';
				} else if (size / 1024 >= 1 && size / 1024 / 1024 < 1) {
					_this.cache = Math.floor((size / 1024) * 100) / 100 + 'KB';
				} else if (size / 1024 / 1024 >= 1) {
					_this.cache = Math.floor((size / 1024 / 1024) * 100) / 100 + 'M';
				}
				console.log(_this.cache, '内存');
				_this.list[3].num = _this.cache;
			});
			//#endif
			// #ifdef H5
			this.cache = 0.1;
			// #endif
		},
		//获取当前版本号
		getNow() {
			let _this =this
			// #ifdef APP-PLUS
			plus.runtime.getProperty(plus.runtime.appid, wgtinfo => {
				console.log(JSON.stringify(wgtinfo));
				console.log(wgtinfo, '当前版本号'); //应用版本号
				_this.edition = wgtinfo.version;
			});
			// #endif
		},
		about() {
			uni.navigateTo({
				url: '../about-loto/about-loto'
			});
		},
		async handleAccountCancel(){
		    this.$refs.popup.open()
		    this.count = 5
		    this.timer = setInterval((i) => {
		     if(this.count>0){
		      this.count --;
		     } else {
		      clearInterval(this.timer)
		     }
		     
		    }, 1000)
		   },
		   handleCancle(){
			   clearInterval(this.timer)
		    this.$refs.popup.close()
		   },
		  async handleAccountCanceldid(){
			  if(this.count>0){
				  return
			  }
			  
			  let r = await writeOffJudge({
			  	nurseId: uni.getStorageSync('userInfo').id
			  })
			  if(!r.success){
			  	uni.showToast({
			  		title:r.codeMsg.msg,
			  		icon: 'none'
			  	})
			  	return
			  }
			  
			  // 注销
			  uni.navigateTo({
			  	url:'../validate/validate?type='+ 9
			  })
			  return
			  
			   let _this = this
			   let rst =await writeOff()
			   console.log(rst,'..............')
			   if(rst.success){
			   	uni.clearStorageSync();
				uni.setStorageSync('deniedPresentPermission','true')
			   	_this.$store.state.attestStatus=''
			   	_this.$store.state.nameStatus=''
			   	_this.$store.state.userInfo=''
			   	// #ifdef APP-PLUS
			   	plus.nativeUI.toast('操作成功!')
			   	// #endif
			   	// uni.showToast({
			   	// 	icon:'none',
			   	// 	title:'操作成功！'
			   	// })
			   	setTimeout(()=>{
			   		uni.reLaunch({
			   			url:'../../login-register/login/login'
			   		})
			   	},200)
			   }else{
			   	// #ifdef APP-PLUS
			   	plus.nativeUI.toast('注销失败!')
			   	// #endif
			   	// uni.showToast({
			   	// 	icon:'none',
			   	// 	title:'注销失败',
			   	// })
			   }
		   },
			moveTo(item){
				let _this = this
				let url = item.url
				if(item.state){
					if(!this.$store.state.attestStatus && item.state==7){
						uni.showModal({
							confirmColor:'#3c8eff',
							content:'应相关国家规定，为确保平台信息安全，需进行执业认证才可继续！',
							success(res) {
								if (res.confirm) {
									uni.navigateTo({
										url:'../../iden/iden/iden'
									})
								} else if (res.cancel) {
									uni.navigateBack({
										delta:1
									})
								}
							}
						})
						return
					}
					let type = item.state
					//验证码
					console.log(type)
					uni.navigateTo({
						url:'../validate/validate?type='+ type
					})
				}else{
					if(item.type == "清除缓存"){
						let _this = this
						uni.showModal({
							title: '提示',
							content: '确定要清楚缓存？',
							confirmColor:'#3C8EFF',
							success: function (res) {
								if(res.confirm){
									// #ifdef APP-PLUS
									//使用plus.cache.clear 清除应用中的缓存数据
										plus.cache.clear(function() {
											plus.nativeUI.toast('清除成功!')
											setTimeout(()=>{
												_this.list[3].num  = '0B'
											},200)
											// uni.showToast({
											// 	title: '清除成功',
											// 	icon: 'success',
											// 	success() {
											// 		
											// 	}
											// })
										});
									// #endif
								}else if(res.cancel)
									console.log('quxiao')
								} 
						});
					}else if(item.type == "注销账号"){
						this.handleAccountCancel()
						return
						uni.showModal({
							title: '提示',
							content: '确定要注销账号？',
							confirmColor:'#3C8EFF',
							success: async function (res) {
								if (res.confirm) {
								
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
				}  else {
					console.log(url);
					uni.navigateTo({
						url: url
					});
				}
			}
		},
		outBack() {
			let _this=this
			// plus.nativeUI.confirm('tuichu',function(e){
			// 	console.log(e.index)
			// },'这是标题',{})
			// return 
			uni.showModal({
				title: '确定退出该账号吗？',
				async success(res) {
					if (res.confirm) {
						//#ifdef APP
						plus.nativeUI.showWaiting()
						//#endif
						let uuid = _this.uuid;
						let ret = await deleteLogined({ uuid });
						if(!ret){
							// #ifdef APP
							plus.nativeUI.closeWaiting()
							// #endif
							return
						}
						console.log(res, '退出登录');
						if (ret.success) {
							// #ifdef APP-PLUS
							plus.nativeUI.closeWaiting()
							// #endif
							uni.clearStorageSync();
							uni.setStorageSync('deniedPresentPermission','true')
							_this.$store.commit('setAttestStatus',false)
							_this.$store.commit('setNameStatus',false)
							_this.$store.commit('setUserInfo','')
							console.log(_this.$store.state.attestStatus,'认证状态',_this.$store.state.nameStatus,'实名',_this.$store.state.userInfo,'用户消息')
							uni.reLaunch({
								url: '../../login-register/login/login?type=1'
							});
						} 
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				},
			});
		},
	},
	components:{
		uniConfirm,
		uniPopup,
	}
};
</script>

<style scoped lang="scss">
.list {
	width: 698rpx;
	height: 108rpx;
	background: rgba(216, 216, 216, 0);
	margin: 0 auto;
	border-bottom: 1rpx solid #f6f6f6;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 20rpx;
	font-size: 28rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #000000;
	box-sizing: border-box;
	position: relative;
}
.title {
	height: 40rpx;
	font-size: 28rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #000000;
	line-height: 40rpx;
}
.icon {
	width: 48rpx;
	height: 48rpx;
}
.num {
	position: absolute;
	right: 70rpx;
	top: 35rpx;
	font-size: 28rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: rgba(0, 0, 0, 0.38);
}
.out_back {
	width: 458rpx;
	height: 96rpx;
	font-size: 28rpx;
	border-radius: 8rpx;
	border: 2rpx solid #3C8EFF;
	color: #3C8EFF;
	margin: 0 auto;
	margin-top: 264rpx;
	line-height: 96rpx;
	text-align: center;
}
.uni-popup{
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: #FFF;
  border-radius: 20rpx;
  .title{
   margin: 32rpx 0;
   font-size: 36rpx;
   font-weight: 500;
   color: #333333;
  }
  .content{
   margin: 0 26rpx;
   padding: 30rpx 22rpx;
   width: 80%;
   background: #F6F6F6;
   border-radius: 20rpx;
   .ltitle{
    font-size: 28rpx;
    color: #333333;
    margin-bottom: 6rpx;
    img{
     position: relative;
     left: -4rpx;
     top: 5rpx;
     height: 32rpx;
     width: 32rpx;
    }
   }
   .li{
    margin-top: 8rpx;
    position: relative;
    left: 24rpx;
    font-size: 24rpx;
    font-weight: 400;
    color: #666666;
    &::before{
     content: '';
     display: inline-block;
     position: absolute;
     left: -20rpx;
     top: 9rpx;
     height: 16rpx;
     width: 16rpx;
     border-radius: 50%;
     background: rgba(51, 51, 51, 1);
    }
   }
   
  }
  .btns{
   width: 100%;
   margin-top: 32rpx;
   display: flex;
   justify-content: space-around;
   border-top: 1rpx solid rgba(229, 229, 229, 1);
   .left,.right{
    height: 106rpx;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
   }
   .right{
    color:rgba(153, 153, 153, 1);
    border-left: 1rpx solid rgba(229, 229, 229, 1);
    &.red{
     color:rgba(234, 32, 39, 1);
    }
   }
  }
 }
</style>
